<extend name="Public/base"/>

<block name="body">
    <style type="text/css">
    
    </style>
 

    <script type="text/javascript" src="__STATIC__/uploadify/jquery.uploadify.min.js"></script>
    <div class="main-title">
        <h2>帖子管理 <button class="btn btn-default btn-return" onclick="javascript:history.back(-1);return false;"><i class="glyphicon glyphicon-share-alt"></i> 返 回</button></h2>
    </div>

     
    <div class="tab-content">
    <form action="" method="post" class="form">
            <div class="form-item form-group">
                <label class="item-label">前台发稿人UID<span class="check-tips"></span></label>
                <div class="controls">
                    <input type="text" class="form-control text input-mini" name="uid" value="{$uid}" /> <a target="_blank" href="{:U('frontUsers/index')}">查询</a>
                </div>
            </div>
            <eq name="circle_id" value="1">
            <div class="form-item form-group">
                <label class="item-label">话题缩略图<span class="check-tips">547*211px(官方话题必须上传)</span></label>
                <div class="controls">
                    <input type="file" id="upload_picture_thumb">
                    <input type="hidden" class="text input-large" name="thumb" id="cover_id_thumb" value="{$thumb}" />
                    <div class="upload-img-box">
                    <notempty name="thumb">
                        <div class="upload-pre-item"><img class="img-thumbnail" src="{:url_format($thumb)}"/></div>
                    </notempty>
                    </div>
                </div>   
                <script type="text/javascript">
                //上传图片
                /* 初始化上传插件 */
                $("#upload_picture_thumb").uploadify({
                    "height"          : 30,
                    "swf"             : "__STATIC__/uploadify/uploadify.swf",
                    "fileObjName"     : "download",
                    "buttonText"      : "上传图片",
                    "uploader"        : "{:U('File/uploadPicture',array('session_id'=>session_id()))}",
                    "width"           : 120,
                    'removeTimeout'   : 1,
                    'fileTypeExts'    : '*.jpeg; *.jpg; *.png; *.gif;',
                    "onUploadSuccess" : uploadpicturethumb,
                    'onFallback' : function() {
                        alert('未检测到兼容版本的Flash.');
                    }
                });
                function uploadpicturethumb(file, data){
                    var data = $.parseJSON(data);
                    var src = '';
                    if(data.status){
                        $("#cover_id_thumb").val(data.path);
                        src = data.url || '__ROOT__' + data.path
                        $("#cover_id_thumb").parent().find('.upload-img-box').html(
                            '<div class="upload-pre-item"><img src="' + src + '"/></div>'
                        );
                    } else {
                        updateAlert(data.info);
                        setTimeout(function(){
                            $('#top-alert').find('button').click();
                            $(that).removeClass('disabled').prop('disabled',false);
                        },1500);
                    }
                }
                </script>
                </div>
            </eq>

            <div class="form-item form-group">
                <label class="item-label">标题<span class="check-tips"></span></label>
                <div class="controls">
                    <input type="text" class="form-control text input-large" name="title" value="{$title}" />
                </div>
            </div>
             
            <div class="form-item form-group">
                <label class="item-label">内容<span class="check-tips"></span></label>
                <div class="controls">
                    <label class="input-large">
                        <textarea class="textarea form-control" rows="3" name="content">{$content}</textarea>
                    </label>
                </div>
            </div>

            <div class="form-item form-group">
                <label class="item-label">媒体类型<span class="check-tips"></span></label>
                <label class="radio-inline" >
                    <input onclick="typechoose(0)" type="radio" name="attachment_type" value="0"  /> 文字
                </label>
                <label class="radio-inline">
                    <input onclick="typechoose(1)" type="radio" name="attachment_type" value="1"  /> 图文
                </label>
                <label class="radio-inline">
                    <input onclick="typechoose(2)" type="radio" name="attachment_type" value="2"  /> 视频
                </label>
            </div>


            <div id="attachment_type_2" class="form-item form-group attachment_type_class">
                <label class="item-label">视频ID<span class="check-tips"></span></label>
                <div class="controls">
                    <input type="text" class="form-control text input-mini" name="video_id" value="{$video.id}" />
                    <a target="_blank" href="{:U('Video/index')}">查询</a>
                </div>
            </div>

            <div id="attachment_type_1" class="form-item form-group cf attachment_type_class">
            <label class="item-label">图片<span class="check-tips">上传后, 请等待读取图片的宽高.. </span></label>
            <div class="controls">
                <div class="controls">
                    <input type="file" id="upload_picture_image">
                    <div class="upload-img-box">
                        <notempty name="pics">
                        <volist name="pics" id="p">
                        <div id="{$key}" class="upload-pre-item" style="position: relative; margin-bottom: 30px; overflow: inherit"><img src="{$p.url|url_format}"/>
                        <input type="hidden" name="pics[]" value="{$p.url}" />
                        <input id="img-scale-0" type="hidden" name="scale[]" value="{$p.scale}" />
                        <a style="position: absolute;top: 0;width: 20px;height: 20px;background: #fff;right: 0;display:block" href="javascript:delPic({$key})">X</a>
                        <span id="img-scale-show-o" style="position: absolute; width:100%; height:20px; bottom: -20px; left: 0; background: #ffffff">{$p.scale}</span>
                        </div>

                        </volist>
                        </notempty>
                    </div>
                </div>
                <script type="text/javascript">
                    function delPic(uuid) {
                        $('#'+uuid).remove();
                    }

                    function loadImgScale(id, img_url) {
                        var img = new Image();
                        // 改变图片的src
                        img.src = img_url;
                        // 加载完成执行
                        img.onload = function(){
                            var value = img.width+':'+img.height;
                         // 打印
                            $('#img-scale-'+id).val(value);
                            $('#img-scale-show-'+id).html(value);
                            alert('宽高读取成功: '+value);
                        };
                    }

                    function uploadCall(file, data) {
                        var data = $.parseJSON(data);
                        var src = '';
                        if(data.status){
                            var uuidstr = uuid();
                            $("#cover_id_image").val(data.path);
                            src = data.url || '__ROOT__' + data.path
                            $("#upload_picture_image").parent().find('.upload-img-box').append(
                                '<div id="'+uuidstr+'" class="upload-pre-item" style="position: relative; margin-bottom: 30px; overflow: inherit"><img src="' + src + '"/>'+
                                '<input type="hidden" name="pics[]" value="'+src+'" />'+
                                '<input id="img-scale-'+uuidstr+'" type="hidden" name="scale[]" />'+
                                '<a style="position: absolute;top: 0;width: 20px;height: 20px;background: #fff;right: 0;display:block" href="javascript:delPic(\''+uuidstr+'\')">X</a>'+
                                '<span id="img-scale-show-'+uuidstr+'" style="position: absolute; width:100%; height:20px; bottom: -20px; left: 0; background: #ffffff"></span>'+
                                '</div>'
                            );
                            loadImgScale(uuidstr, src);
                        } else {
                            updateAlert(data.info);
                            setTimeout(function(){
                                $('#top-alert').find('button').click();
                                $(that).removeClass('disabled').prop('disabled',false);
                            },1500);
                        }
                    }

                </script> 
                {:hook('adminPicUpload', array('id'=>"upload_picture_image",'return'=>"cover_id_image", 'type' => 'path', 'isMulti' => 1, 'name'=>'pic[]', 'delcall' => 'delPic', 'uploadcall' => 'uploadCall'))}                 
            </div>
        </div>

            <div class="form-item form-group">
                <label class="item-label">状态<span class="check-tips"></span></label>
                <label class="radio-inline" >
                    <input type="radio" name="status" value="1"  /> 显示
                </label>
                <label class="radio-inline">
                    <input type="radio" name="status" value="0"  /> 不显示
                </label>
            </div>

            <div class="form-item form-group">
                <label class="item-label">是否置顶<span class="check-tips">请控制置顶个数</span></label>
                <label class="radio-inline">
                    <input type="radio" name="is_top" value="0"  /> 不置顶
                </label>
                <label class="radio-inline" >
                    <input type="radio" name="is_top" value="1"  /> 置顶
                </label>
            </div>

        </div>

        <div class="form-item form-action">
            <input type="hidden" name="id" value="{$_id}" />
            <input type="hidden" name="circle_id" value="{$circle_id}" />
            <button class="btn submit-btn ajax-post btn-success btn-block" id="submit" type="submit" target-form="form">确 定</button>
            <!-- <button class="btn btn-return" onclick="javascript:history.back(-1);return false;">返 回</button> -->
        </div>
    </form>
    </div>
    <div id="video-pre">
        <video controls="controls" autoplay="autoplay"></video>
    </div>
</block>

<block name="script">
    <script src="__STATIC__/thinkbox/jquery.thinkbox.js"></script>
    <script type="text/javascript">
        //导航高亮
        highlight_subnav('{:U('Video/index')}');
        Think.setValue("status", '{$status|default=1}');
        Think.setValue("is_top", '{$is_top|default=0}');
        Think.setValue("attachment_type", '{$attachment_type|default=0}');
        
        function typechoose(id) {
            $('.attachment_type_class').hide();
            if (id > 0)
            $('#attachment_type_'+id).show();
        }

        typechoose({$attachment_type|default=0});

    </script>
</block>
